package com.ithema.manger2.service;

import com.ithema.manger2.dao.StudentDao;
import com.ithema.manger2.domain.Student;

public class StudentService {
    //添加学生
    public boolean addStudent(Student stu) {
        //调用StudentDao的方法addStudent
        StudentDao studentDao=new StudentDao();
        return studentDao.addStudent(stu);
    }
//查看学号是否存在
    public boolean isExist(String sid) {
        //调用StudentDao的方法findAllStudent
        StudentDao studentDao=new StudentDao();
        Student[] stu=studentDao.findAllStudent();
        //定义初始值
        boolean flag=false;
        //遍历数组
        for (int i = 0; i < stu.length; i++) {
            Student stus=stu[i];
            if(stus!=null&&sid.equals(stus.getSid())){
                flag=true;
            }
        }return flag;
    }
//调用所有学生
    public Student[] findAllStudent() {
        //调用StudentDao的方法findAllStudent
        StudentDao studentDao=new StudentDao();
        return studentDao.findAllStudent();
    }
//删除学生传递
    public void deletStudent(String sid) {
        //调用StudentDao的方法findAllStudent
        StudentDao studentDao=new StudentDao();
        studentDao.deletStudent(sid);
    }
//修改学生传递
    public void updateStudent(String updateSid, Student updateStu) {
        //调用StudentDao的方法updateStudent
        StudentDao studentDao=new StudentDao();
        studentDao.updateStudent(updateSid,updateStu);
    }
}
